package com.kh.tool.exceldatachecker;

import lombok.Data;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Data
public class ExcelColumns {
    private String key;
    private String value;
    private boolean repeatCheck;
    private boolean notNullCheck;
    private List<ExcelDataParser.BusinessChecker> formatCheckers;
    private List<ExcelDataParser.BusinessChecker> dbCheckers;

    public ExcelColumns(String key,String value,boolean notNullCheck, boolean repeatCheck) {
        this.key = key;
        this.value = value;
        this.formatCheckers = new ArrayList<>();
        this.dbCheckers = new ArrayList<>();
        this.notNullCheck = notNullCheck;
        this.repeatCheck = repeatCheck;
        if (notNullCheck) {
            formatCheckers.add((toBeVerified) -> {
                if (StringUtils.isEmpty(toBeVerified.getValue()) || toBeVerified.getValue().equals("-")) {
                    toBeVerified.setErrorMsg(toBeVerified.getValue()+"为空");
                    return false;
                }
                return true;
            });
        }
    }

    public ExcelColumns(String key, String value) {
        this(key,value,true,true);
    }

    public ExcelColumns(String key, String value, boolean repeatCheck) {
        this(key,value,true,repeatCheck);
    }

    public ExcelColumns addFormatCheckers(ExcelDataParser.BusinessChecker checker) {
        this.formatCheckers.add(checker);
        return this;
    }

    public ExcelColumns addDbCheckers(ExcelDataParser.BusinessChecker checker) {
        this.dbCheckers.add(checker);
        return this;
    }
}
